package com.hr.service;

import com.hr.dao.WantedDAO;
import com.hr.model.UW;
import com.hr.model.User;
import com.hr.model.Wanted;
import com.hr.util.AuthUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WantedService
{
    @Autowired
    WantedDAO wantedDAO;

    public Wanted getWantedByWId(int wid)
    {
        return wantedDAO.getWantedByWId(wid);
    }

    public List<Wanted> getWantedsByCId(int cid)
    {
        return wantedDAO.getWantedsByCId(cid);
    }

    public List<UW> getUWsByWId(int wid)
    {
        return wantedDAO.getUWsByWId(wid);
    }

    public List<Wanted> getAllWanteds()
    {
        return wantedDAO.getAllWanteds();
    }

    public void insertWanted(Wanted wanted)
    {
        wantedDAO.insertWanted(wanted);
    }

    public List<Wanted> getWantedsByUId()
    {
        return wantedDAO.getWantedsByUId(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
    }

    public String getWantedStatusByU_W_Id(int uid,int wid)
    {
        return wantedDAO.getWantedStatusByU_W_Id(uid,wid);
    }

    public UW getUWByU_W_Id(int uid,int wid)
    {
        return wantedDAO.getUWByU_W_Id(uid,wid);
    }

    public boolean isHrOfWanted(int wid)
    {
        Wanted wanted=wantedDAO.getWantedByWId(wid);

        return AuthUtil.checkByCId(wanted.getCompany().getId());
    }

    public void insertUW(int uid,int wid,String status)
    {
        wantedDAO.insetUW(uid,wid,status);
    }

    public void updateUW(int uid,int wid,String status)
    {
        wantedDAO.updateUW(uid,wid,status);
    }

    public void checkWanted(int wid,boolean enable)
    {
        wantedDAO.checkWanted(wid,enable);
    }
}
